Changes In "Not" Operator Syntax
The Regular Expression 'not' operator, !, was revised in Search and Replace version 3.1 to improve reliability and predictability of ! expressions. Longtime Search and Replace users may have noted in the past that when ! was combined with other operators it was sometimes difficult to anticipate what aspect of the total expression would be affected by the ! character. The syntax for ! is now explicit and, we hope, easier to understand & debug.
Previous users should familiarize themselves with the new syntax. Previous ! syntax may not work as it did before and existing scripts may need revision.
In general, the ! syntax now requires explicit expressions for both the string(s) to be found and the string(s) to not find. This can be thought of as "find something except what is specified by the ! expression".
For example, under the older syntax, to find "mat", "rat" or "sat" except in "bat" or "cat", the expression was !(b|c)at. Now the expression would be ?at!((b|c)at). In words, this can be thought of as "find something ending in 'at' except if it ends in 'b'at or 'c'at.
See ! - Not Operator for additional examples.
Notes:
In most cases you will need to specify a wild card operator of some type in the component of your expression representing the 'positive' hit. Referring to the above, the ? is necessary. You could also use any of the other operators.
The 'not' component of the expression should be enclosed in ( ) or [ ]. Complex expressions may included inside the paren or brackets.
!() may be employed as a type of "and" operator. For example, div*!()(center|right) will work.
When using ! with replacements be sure to specify the search expression literals in your replacement expression. For example, if you employed the search expression ?at!((b|c)at) in a replacement to put quote characters around all strings ending in 'at' (except if they begin with 'b' or 'c'), the replacement expression would be "%1at". The 'at' string must be specified in the replacement expression because that is a literal in the search expression.
The components of the expression following the ! operator may not be accessed via an %n operator in a replace string. For example, in the expression div*!()(center|right) there would be no %2 operator for use in a replace expression.